package com.example.test.qtnet

import com.example.test.support.QianToonApiUtil
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type

/**
 * @Package com.example.test.http
 * @ClassName NetBean
 * @Author caostgrace
 * @Date 2021/4/8
 * @Email liaobing@qiantoon.com
 * @Desc
 */

//请求入参bean
data class BaseRequestBean(
        val head: RequestHead,
        val data: String
)

data class RequestHead(
        @SerializedName("auth_token")
        @Expose
        val authToken: String,
        @SerializedName("Key")
        @Expose
        val key: String = "A13H212J1FSDWWE",
        @SerializedName("TimeStamp")
        @Expose
        val timeStamp: String
)

//响应bean
data class BaseResponseBean(
        val head: ResponseHead,
        val data: String?
) {
    fun <T> getDecryptData(clazz: Class<T>): T? {
        return QianToonApiUtil.sm4Decrypt(head.timeStamp, data, clazz)
    }

    fun <T> getDecryptDataByType(type: Type): T? {
        return QianToonApiUtil.sm4DecryptByType(head.timeStamp, data, type)
    }

    /*** 获取解密后的字符串  */
    fun getDecryptDataStr(): String? {
        return QianToonApiUtil.sm4Decrypt(head.timeStamp, data)
    }
}

data class ResponseHead(
        @SerializedName("Timestamp")
        @Expose
        val timeStamp: String,
        @SerializedName("resultcode")
        @Expose
        val resultCode: String,
        @SerializedName("errmsg")
        @Expose
        val errMsg: String
)

data class TokenBean(val Token:String)